﻿var map = new BMap.Map("allmap");
if ($("#Longitude").val() != 0)
{
    var point = new BMap.Point($("#Longitude").val(), $("#Latitude").val());
    map.centerAndZoom(point, parseInt($("#Zoom").val()));
    map.clearOverlays();
    var marker = new BMap.Marker(point);
    map.addOverlay(marker);
}
else
{
    map.centerAndZoom("福州", 13);
}
map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
map.addEventListener("click", function (e)
{
    $("#Longitude").val(e.point.lng);
    $("#Latitude").val(e.point.lat);
    $("#Zoom").val(map.getZoom());

    map.clearOverlays();
    var marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat));
    map.addOverlay(marker);
});

function search()
{
    var local = new BMap.LocalSearch(map, {
        renderOptions: { map: map }
    });
    var name = $("#Name").val();
    local.search(name);
}

function searchBy(element)
{
    var local = new BMap.LocalSearch(map, {
        renderOptions: { map: map }
    });
    var name = $(element).val();
    local.search(name);
}